<template>
  <div class="app-container">
    <el-row :gutter="20" class="mb8">
      <el-col :span="1.5">
        <el-button round icon="el-icon-back" @click="goBack">返回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button-group>
          <el-button
            type="success"
            @click="handleAddDisease"
            v-if="isShowAddDisease"
            >添加疾病</el-button
          >
          <el-button
            type="success"
            @click="handleAddReview"
            v-if="tabActiveName == 5"
            >添加复查</el-button
          >
          <el-button
            type="success"
            @click="handleAddFollow"
            v-if="tabActiveName == 7"
            >添加随访</el-button
          >
          <el-button
            type="danger"
            @click="handleReject"
            v-if="tabActiveName == 1"
            >拒检</el-button
          >
          <!-- <el-button type="danger" @click="handleDelete" :disabled="true">
            删除
          </el-button>
          <el-button @click="handleReset">重置</el-button> -->
          <el-button type="success" @click="handleStaging">暂存</el-button>
          <el-button type="primary" @click="handleCheckAll">总检</el-button>
        </el-button-group>
      </el-col>
      <el-col :span="1.5">
        <el-button-group>
          <!-- <el-button @click="handleDeleteStrong">强制删除</el-button> -->
          <el-button type="success" @click="handleReset">刷新</el-button>
        </el-button-group>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-row :gutter="20">
      <!-- 体检人信息描述 -->
      <el-col :span="4">
        <usr-info ref="usrInfo"></usr-info>
      </el-col>
      <!-- tab 项目 -->
      <el-col :span="20">
        <table-form
          ref="tableForm"
          @tabActiveChange="getTabActiveName"
        ></table-form>
      </el-col>
    </el-row>

    <!-- 添加疾病对话框 -->
    <el-dialog
      :title="diseaseTitle"
      :visible.sync="diseaseOpen"
      width="700px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-table v-loading="loading" :data="diseaseList" highlight-current-row>
        <el-table-column label="名称" align="center" prop="name" />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleSelect(scope.row)">
              选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="diseaseTotal > 0"
        :total="diseaseTotal"
        :page.sync="queryParams.skipCount"
        :limit.sync="queryParams.maxResultCount"
        @pagination="getDiseaseList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>

    <!-- 复查项目对话框 -->
    <el-dialog
      :title="reviewTitle"
      :visible.sync="reviewOpen"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="reviewForm"
        :model="reviewForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="复查项目" prop="projectId">
          <el-select
            v-model="reviewForm.projectId"
            filterable
            clearable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in reviewList"
              :key="item.projectId"
              :label="item.projectName"
              :value="item.projectId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="复查时间" prop="reviewTime">
          <el-date-picker
            v-model="reviewForm.reviewTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitReviewForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>

    <!-- 对话框 -->
    <el-dialog
      :title="followTitle"
      :visible.sync="followOpen"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="followForm"
        :model="followForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="随访项目" prop="projectId">
          <el-select
            v-model="followForm.projectId"
            placeholder="请选择"
            filterable
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in followList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="随访时间" prop="date">
          <el-date-picker
            v-model="followForm.date"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFollowForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import UsrInfo from "../components/UsrInfo";
import TableForm from "../components/TableForm";
export default {
  name: "editForm",
  components: {
    UsrInfo,
    TableForm,
  },
  props: {},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 添加疾病对话框标题
      diseaseTitle: "",
      // 新增疾病对话框是否显示弹出层
      diseaseOpen: false,
      // 疾病列表
      diseaseList: [
        {
          id: "1",
          name: "111",
        },
        {
          id: "2",
          name: "222",
        },
      ],
      // 查询参数
      queryParams: {
        skipCount: 0,
        maxResultCount: 10,
      },
      // 疾病总数
      diseaseTotal: 0,
      // 新增复查对话框标题
      reviewTitle: undefined,
      // 新增复查对话框是否显示弹出层
      reviewOpen: false,
      // 新增复查表单参数
      reviewForm: {},
      // 复查项目
      reviewList: [
        {
          projectId: "1",
          projectName: "111",
          reviewTime: "2021-01-01",
        },
        {
          projectId: "2",
          projectName: "222",
          reviewTime: "2021-01-01",
        },
      ],
      rules: {},
      // 复查记录对话框标题
      followTitle: "",
      // 复查记录对话框是否显示弹出层
      followOpen: false,
      // 复查记录表单
      followForm: {},
      followList: [
        {
          value: "1",
          label: "111",
        },
        {
          value: "2",
          label: "222",
        },
      ],
      // 子组件tabActiveName
      tabActiveName: "",
    };
  },
  computed: {
    // 添加疾病按钮显示
    isShowAddDisease() {
      if ([3, 4, 6].includes(parseInt(this.tabActiveName))) {
        return true;
      } else {
        return false;
      }
    },
  },
  methods: {
    // 返回
    goBack() {
      this.$router.back();
    },
    // 获取疾病表格数据
    getDiseaseList() {},
    // 选择疾病
    handleSelect(row) {},
    // 获取子组件tabActiveName
    getTabActiveName(val) {
      this.tabActiveName = val;
      // console.log("父组件获得子组件传过来的 tabActiveName", val);
    },
    // 添加疾病
    handleAddDisease(row) {
      this.reset();
      this.diseaseTitle = "添加疾病";
      this.diseaseOpen = true;
    },
    // 总检
    handleCheckAll() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("有【14】个未检项目，是否强制总检？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("总检成功");
        })
        .catch(() => {});
    },
    // 刷新
    handleReset() {},
    // 暂存
    handleStaging() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认暂存？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("暂存成功");
        })
        .catch(() => {});
    },
    // 删除
    handleDelete() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // 拒检
    handleReject() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认拒检？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("拒检成功");
        })
        .catch(() => {});
    },
    // 重置
    handleReset() {},
    // 新增复查
    handleAddReview() {
      this.reset();
      this.reviewOpen = true;
      this.reviewTitle = "新增复查";
    },
    // 新增随访
    handleAddFollow() {
      this.reset();
      this.followOpen = true;
      this.followTitle = "新增随访";
    },
    // 取消按钮
    cancel() {
      this.reviewOpen = false;
      this.diseaseOpen = false;
      this.followOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.reviewForm = {
        id: undefined,
        projectId: undefined,
        reviewReason: undefined,
        reviewTime: undefined,
      };
      this.followForm = {
        id: undefined,
        date: undefined,
      };

      this.resetForm("reviewForm");
      this.resetForm("followForm");
    },
    // 新增复查提交
    submitReviewForm() {
      console.log(this.reviewForm);
    },
    // 新增随访提交
    submitFollowForm() {
      console.log(this.followForm);
    },
  },
};
</script>

<style>
</style>